package com.dt76.smallloanbackendservice.service.xiaohao.impl;

import com.dt76.smallloanbackendservice.mapper.xiaohao.ApprovalLoanMapper;
import com.dt76.smallloanbackendservice.pojo.xiaohao.ApprovalLoan;
import com.dt76.smallloanbackendservice.pojo.xiaohao.BorrowOrder;
import com.dt76.smallloanbackendservice.pojo.xiaohao.BorrowOrderQuery;
import com.dt76.smallloanbackendservice.service.xiaohao.ApprovalLoanService;
import com.dt76.smallloanbackendservice.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ApprovalLoanServiceImpl implements ApprovalLoanService {

    @Autowired
    private ApprovalLoanMapper approvalLoanMapper;

    @Override
    public int insertApproveLoan(ApprovalLoan approvalLoan) {
        return approvalLoanMapper.addApproveLoan(approvalLoan);
    }

    @Override
    public Page qryAllLoanOrder(Integer currentPageNo, BorrowOrderQuery borrowOrderQuery) {
        Page page = new Page();
        page.setPageIndex(currentPageNo);
        String startTime = "";
        String endTime = "";
        if (borrowOrderQuery.getQueryTime() != null && !borrowOrderQuery.getQueryTime().equals("")) {
            startTime = borrowOrderQuery.getQueryTime().substring(0, 10);
            System.out.println(startTime);
            endTime = borrowOrderQuery.getQueryTime().substring(13, 23);
            System.out.println(endTime);
        }
        //得到符合条件的所有结果
        page.setTotalCount(approvalLoanMapper.qryLoanOrderCount(borrowOrderQuery.getQueryBoId(), borrowOrderQuery.getQueryName(), borrowOrderQuery.getQueryContractID(), startTime, endTime, borrowOrderQuery.getQueryType(), borrowOrderQuery.getQueryBoTypeList()));
        page.setRows(approvalLoanMapper.qryAllLoanOrder((page.getPageIndex() - 1) * page.getPageSize(), page.getPageSize(), borrowOrderQuery.getQueryBoId(), borrowOrderQuery.getQueryName(), borrowOrderQuery.getQueryContractID(), startTime, endTime, borrowOrderQuery.getQueryType(), borrowOrderQuery.getQueryBoTypeList()));
        return page;
    }

    @Override
    public Page qryAllHanderOrder(Integer currentPageNo, BorrowOrderQuery borrowOrderQuery) {
        Page page = new Page();
        page.setPageIndex(currentPageNo);
        String startTime = "";
        String endTime = "";
        if (borrowOrderQuery.getQueryTime() != null && !borrowOrderQuery.getQueryTime().equals("")) {
            startTime = borrowOrderQuery.getQueryTime().substring(0, 10);
            System.out.println(startTime);
            endTime = borrowOrderQuery.getQueryTime().substring(13, 23);
            System.out.println(endTime);
        }
        //得到符合条件的所有结果;
        page.setTotalCount(approvalLoanMapper.qryAllHanderOrderCount(borrowOrderQuery.getQueryBoId(), borrowOrderQuery.getQueryName(), borrowOrderQuery.getQueryContractID(), startTime, endTime, borrowOrderQuery.getQueryType(),borrowOrderQuery.getQueryBoType(), borrowOrderQuery.getQueryBoTypeList()));
        page.setRows(approvalLoanMapper.qryAllHanderOrder((page.getPageIndex() - 1) * page.getPageSize(), page.getPageSize(), borrowOrderQuery.getQueryBoId(), borrowOrderQuery.getQueryName(), borrowOrderQuery.getQueryContractID(), startTime, endTime, borrowOrderQuery.getQueryType(), borrowOrderQuery.getQueryBoType(),borrowOrderQuery.getQueryBoTypeList()));
        return page;
    }
}
